#ifndef DBTABBASE_H
#define DBTABBASE_H
#include <QLatin1String>
#include <QSqlDatabase>
#include <QDebug>
#include <QMap>
#include "database.h"
#include "databasequery.h"

#ifdef MYSQL
#define AUTO_INCREMENT "auto_increment"
#else
#define AUTO_INCREMENT "AUTOINCREMENT"
#endif

class DBTabBase :public QObject
{
    Q_OBJECT
public:
    struct ColumnInfo{
        const char *columnName;
        const char *keyString;
    };
    static const char* _ID;
    static QStringList getColumnNameList(const QString &tabName,QSqlDatabase &db=DataBase::getDataBase());
    static void createTab(const QLatin1String &name, const ColumnInfo infoTab[],QSqlDatabase &db=DataBase::getDataBase());

    const QLatin1String &tabName();
    virtual int getVersion(QSqlDatabase &db=DataBase::getDataBase());

    virtual QStringList getColumnNameList(QSqlDatabase &dbb=DataBase::getDataBase());
    virtual void createTab(QSqlDatabase &db=DataBase::getDataBase())=0;

    virtual bool syncSelect(DataBaseQuery &query);
    virtual QString queryData2String(const DataBaseQuery &query);
    
    virtual void resetTable(QSqlDatabase &db=DataBase::getDataBase()){
        DataBaseQuery query(db);
        query.resetTable(mTabName);
    }
    virtual void insertRow(const QStringList &line);
    virtual void setVersion(int ver,QSqlDatabase &db=DataBase::getDataBase());
    static bool isExist(const QString &tabName,const QString &fieldName,const QString &name);
signals:
    void db_updated();

protected:
    DBTabBase(const QLatin1String &name,QObject *obj=nullptr);
    const QLatin1String mTabName;

private:
    DBTabBase(const DBTabBase&)=delete ;
};



#endif // DBTABBASE_H
